# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=owtf
pkgver=v2.6.0.r161.g9a616f5
pkgrel=1
epoch=1
groups=('blackarch' 'blackarch-webapp' 'blackarch-automation'
        'blackarch-scanner' 'blackarch-fuzzer')
pkgdesc='The Offensive (Web) Testing Framework.'
url='https://www.owasp.org/index.php/OWASP_OWTF'
license=('custom')
arch=('any')
depends=('python' 'python-virtualenv' 'postgresql' 'python-pyaml' 'python-yaml')
optdepends=('tor' 'proxychains-ng' 'skipfish' 'metagoofil' 'set' 'wpscan'
            'theharvester' 'metasploit' 'whatweb' 'cms-explorer' 'whapiti'
            'arachini' 'dnsrecon' 'dirbuster' 'w3af' 'lbd' 'nikto' 'tlssled'
            'httprint' 'hydra' 'wafw00f' 'websecurify' 'hoppy')
makedepends=('git')
options=('!strip')
source=("git+https://github.com/$pkgname/$pkgname.git"
        'LICENSE'
        'ssl-cipher-check.pl'
        'BIG-IP_cookie_decoder.py')
sha512sums=('SKIP'
            '9a46df3e73cb5bfd87b266d591010497368e9d1e2980c3f7c0fbbe7832a37db62fba3f6b72015b9e577f0080073536f5b6a1dfa05316bcc9c4697f34a9f5dc7c'
            'db582f5008530581f02a2073496dfc79a2140fab7b5d477f27bef20d8d72d4b8c88ee9ce3cdaec73530b994fa17234aa7ca18de90ba61fbc59aa85bed485bd15'
            '138e97b092c3b7daaceb434a1478673dd9e558bf89d080ca8886b89ced212e1ec3d9af3148e7d9b32833be1b5ae764f268dfe5efc32e17dc704fac7024499d0d')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i 's|sqlalchemy_mixins==1.1|sqlalchemy_mixins|g' requirements/base.txt
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md
  install -Dm 644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm *.md

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cp "$pkgdir/usr/share/$pkgname/bin/$pkgname" \
    "$pkgdir/usr/share/$pkgname/_${pkgname}"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
source venv/bin/activate
exec python _${pkgname} "\$@"
EOF

  chmod a+x "$pkgdir/usr/bin/$pkgname"
}

